import { defineConfig } from "rollup";
import {
    BundleFormat, // 工具包格式
    PreferenceOption,
    getPreferenceOption,
    mergePreferenceOption,
    getOutDir,
    setOutDir,
    getBundleBaseName,
    setBundleBaseName,
    getExternalOption,
    setExternalOption,
    mergeExternalOption,
    getGlobalsOption,
    setGlobalsOption,
    mergeGlobalsOption,
    getMinify,
    setMinify,
    getPlugins,
    setPlugins,
    mergePlugins,
    singleChunkInputs,
    singleChunkOutputs,
    singleChunkOutputsByFilename,
    buildRollupConfig,
} from "@sfx-config/rollups";
// ----------------------------------------------------------------------------
// option.outDir
setOutDir("dist");

// option.bundleBaseName
setBundleBaseName("index");

// option.externals
const externals = [
    // "@rollup/plugin-typescript"
];
mergeExternalOption(externals);

// option.globals
const globals = {
    // "@rollup/plugin-typescript": "typescript"
};
mergeGlobalsOption(globals);

// option.plugins
const plugins = [
    //
];
mergePlugins(plugins);
// ----------------------------------------------------------------------------
const minify = getMinify();
const bundleName = getBundleBaseName();
const inputs = singleChunkInputs("src/index.ts");
const outputs = [
    // by formatting
    singleChunkOutputs(BundleFormat.AMD),
    singleChunkOutputs(BundleFormat.CJS),
    singleChunkOutputs(BundleFormat.ESM),
    singleChunkOutputs(BundleFormat.UMD),
    singleChunkOutputs(BundleFormat.IIFE),
    singleChunkOutputs(BundleFormat.SYSTEM),
    // default
    singleChunkOutputsByFilename(`${bundleName}.js`, BundleFormat.ESM),
    // unpkg
    // singleChunkOutputsByFilename(`sfx-test.min.js`, BundleFormat.UMD, minify)
];
const rollupConfig = buildRollupConfig(inputs, outputs);
// ----------------------------------------------------------------------------
export default defineConfig(rollupConfig);
